package com.sky.controller.user;

import com.sky.dto.*;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OrdersService;
import com.sky.vo.OrderSubmitVO;
import com.sky.vo.OrderVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user/order/")
@Api(tags = "C端-订单接口")
public class OrdersUserController {

    @Autowired
    OrdersService ordersService;

    @PostMapping("submit")
    @ApiOperation("用户下单")
    public Result<OrderSubmitVO> submitOrders(@RequestBody OrdersSubmitDTO ordersSubmitDTO) {
        OrderSubmitVO vo = ordersService.submitOrders(ordersSubmitDTO);
        return Result.success(vo);
    }

    @PutMapping("/payment")
    @ApiOperation("C端-小程序发起支付")
    public Result payment(@RequestBody OrdersPaymentDTO ordersPaymentDTO) {
        ordersService.payment(ordersPaymentDTO);
        return Result.success();
    }

    @PutMapping("cancel/{id}")
    @ApiOperation("取消订单")
    public Result cancelItem(@PathVariable Long id) {
        ordersService.cancelItem(id);
        return Result.success();
    }

    @GetMapping("historyOrders")
    @ApiOperation("查询历史订单")
    public Result<PageResult> pageHistory(OrdersPageQueryDTO ordersPageQueryDTO) {
        PageResult pageResult = ordersService.pageHistory(ordersPageQueryDTO);
        return Result.success(pageResult);
    }

    /**
     * 再来一单功能
     *
     * @param id
     * @return
     */
    @PostMapping("/repetition/{id}")
    @ApiOperation("C端-再来一单")
    public Result OneMoreOrder(@PathVariable Long id) {
        ordersService.OneMoreOrder(id);
        return Result.success();
    }

    /**
     * 查询订单详情
     *
     * @param id
     * @return
     */
    @GetMapping("/orderDetail/{id}")
    @ApiOperation("C端-查询订单详情")
    public Result orderDetail(@PathVariable("id") Long id) {
        OrderVO orderVO = ordersService.findOrderDetail(id);
        return Result.success(orderVO);
    }
}
